package com.kt.mes.service.impl;

import java.util.Date;
import java.util.List;

import com.kt.mes.domain.ProductStoreList;
import com.kt.mes.service.IProductStoreListService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.kt.mes.mapper.ProductStoreMapper;
import com.kt.mes.domain.ProductStore;
import com.kt.mes.service.IProductStoreService;

/**
 * 成品库Service业务层处理
 * 
 * @author lzc
 * @date 2021-01-22
 */
@Service
public class ProductStoreServiceImpl implements IProductStoreService 
{
    @Autowired
    private ProductStoreMapper productStoreMapper;
    @Autowired
    private IProductStoreListService productStoreListService;

    /**
     * 查询成品库
     * 
     * @param id 成品库ID
     * @return 成品库
     */
    @Override
    public ProductStore selectProductStoreById(Long id)
    {
        return productStoreMapper.selectProductStoreById(id);
    }

    /**
     * 查询成品库列表
     * 
     * @param productStore 成品库
     * @return 成品库
     */
    @Override
    public List<ProductStore> selectProductStoreList(ProductStore productStore)
    {
        return productStoreMapper.selectProductStoreList(productStore);
    }

    /**
     * 新增成品库
     * 
     * @param productStore 成品库
     * @return 结果
     */
    @Override
    public int insertProductStore(ProductStore productStore)
    {
        productStore.setCreateTime(DateUtils.getNowDate());
        return productStoreMapper.insertProductStore(productStore);
    }

    /**
     * 修改成品库
     * 
     * @param productStore 成品库
     * @return 结果
     */
    @Override
    public int updateProductStore(ProductStore productStore)
    {
        productStore.setUpdateTime(DateUtils.getNowDate());
        return productStoreMapper.updateProductStore(productStore);
    }

    /**
     * 批量删除成品库
     * 
     * @param ids 需要删除的成品库ID
     * @return 结果
     */
    @Override
    public int deleteProductStoreByIds(Long[] ids)
    {
        return productStoreMapper.deleteProductStoreByIds(ids);
    }

    /**
     * 删除成品库信息
     * 
     * @param id 成品库ID
     * @return 结果
     */
    @Override
    public int deleteProductStoreById(Long id)
    {
        return productStoreMapper.deleteProductStoreById(id);
    }


    //入库成品库(1-9)
    public void inProStoreByOid(int areaNum){

        //1.先删除库存



        //2. 直接入子表
        ProductStoreList productStoreList=new ProductStoreList();
        productStoreList.setTpsId(Long.valueOf(areaNum));//库位号
        productStoreList.setmId(""); //成品号
        productStoreList.setAvaQty(1L);
        productStoreList.setSumQty(1L);
        productStoreList.setCreateTime(new Date());

        productStoreListService.insertProductStoreList(productStoreList);

        // 入库记录





    }

}
